"""@Project -> File   ：python -> 02.银行登陆系统
   @IDE    ：PyCharm
   @Author ：PengLinxi
   @Date   ：2021/12/11 19:54
"""


# 使用面向对象做一个ATM（存取款功能）
# ATM类
#   属性： 钱、区域
#   方法：（存取）
#        用户可以过来取钱
#        取了钱ATM的钱也会减少
#        取了钱账户的钱也会减少
# 用户类
#  属性：用户名 ，密码，账户金额，账户金额
# 要求：
#      菜单   有登陆验证


class User():

    user_list = [{"username":"plx","password":"plx","user_money":0},
                 {"username":"xixi","password":"xixi","user_money":10000}]


    def func1(self):
        print("欢迎使用".center(50,"*"))
        while 1:
            self.username = input("请输入用户名:")
            self.password = input("请输入密码:")
            if self.username in list(map(lambda x:x['username'],User.user_list)) and self.password in list(map(lambda x:x['password'],User.user_list)):
                print("登录成功")

                for i in User.user_list:
                    if i['username'] == self.username:
                        self.money = i["user_money"]
                print(f"您的账户余额为{self.money}")

                return {"username":self.username,"password":self.password,"user_money":self.money}
                # return self.money

            else:
                print("登录失败，请重新输入")

    def func2(self,user_dict):
        self.user_dict = user_dict

        for i in User.user_list:
            if i['username'] == self.user_dict['username']:
                i['user_money'] = self.user_dict['user_money']
                self.money = i["user_money"]

        print(f"您的账户余额为{self.money}")


class ATM():

    area = "changsha"
    atm_money = 100000
    user_list = [{"username": "plx", "password": "plx", "user_money": 0},
                 {"username": "xixi", "password": "xixi", "user_money": 10000}]


    def save_money(self, user_dict):
        self.user_dict = user_dict
        # self.list_user = self.user_dict['username']
        self.list_money = self.user_dict['user_money']
        # print(self.list_user)
        # print(self.list_money)
        money = int(input("请输入存放金额："))
        ATM.atm_money += money
        self.list_money += money
        # return self.list_money
        self.user_dict['user_money'] = self.list_money
        # print(self.user_dict)
        print(f"ATM机里面的余额为{ATM.atm_money}")
        user.func2(self.user_dict)



    def draw_money(self,user_dict):

        self.user_dict = user_dict
        self.list_money = self.user_dict['user_money']

        while 1:
            money = int(input("请输入提取金额："))
            if money<=self.list_money and money<=ATM.atm_money:
                ATM.atm_money -= money
                self.list_money -= money

                self.user_dict['user_money'] = self.list_money
                # return self.user_dict
                print(f"ATM机里面的余额为{ATM.atm_money}")
                user.func2(self.user_dict)
                return 0
            else:
                print("输入错误，请重新输入提取金额")



user = User()
a = user.func1()
# print(a)

print("执行ATM类")
atm1 = ATM()
print("1.存钱")
print("2.取钱")
print("3.退出系统")
while 1:
    choose_function = input("请选择你所要执行的功能：")
    if choose_function == '1':
        # b =  atm1.save_money(a)
        # print(b)
        atm1.save_money(a)

    elif choose_function == '2':
        atm1.draw_money(a)


    elif choose_function =='3':
        print("退出系统")
        break
    else:
        print("输入有误，请重新输入")

